
package com.kweative.model.relation;

import com.kweative.model.Index;
import com.kweative.model.Table;
import com.kweative.model.data.Row;
import com.kweative.model.exception.ColumnAlreadyExistsException;
import com.kweative.model.exception.IndexNotFoundException;
import com.kweative.model.column.ColumnInteger;
import com.kweative.model.query.SetterStatement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author henrik
 */
public class RelationOne2Many<P extends Table,C extends Table> extends RelationOne2One<P, C> implements ISimpleRelation<P,C> {
    public RelationOne2Many(P child) {
        super(child);
    }

    @Override
    protected void makeStructure() {
        String indexName = String.format("%s_o2m",getParent().getName());
        String colName = String.format("%s_key",indexName);
        parentColumn = getParent().__primary;

        Index ix = getChild().addIndex(new Index(indexName, Index.Type.INDEX));
        try {
            childColumn = getChild().addColumn(new ColumnInteger(colName), ix);
        } catch (IndexNotFoundException ex) {
            Logger.getLogger(RelationOne2Many.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ColumnAlreadyExistsException ex) {
            Logger.getLogger(RelationOne2Many.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
